package guda.mrpc.core;

import guda.mrpc.core.api.Request;

import java.util.Arrays;
import java.util.Map;

/**
 * Created by well on 17/5/21.
 */
public class RpcRequest implements Request {

    private String requestId;
    private RequestKey requestKey;
    private String methodName;
    private Class<?>[] parameterTypes;
    private Object[] parameters;
    private Map<String,String> attach;

    //unit seconds
    private int timeout = 6;

    private boolean async ;

    private boolean hasResult=true;

    @Override
    public RequestKey getKey() {
        return requestKey;
    }

    public int getTimeout() {
        return timeout;
    }

    public void setTimeout(int timeout) {
        this.timeout = timeout;
    }

    public RpcRequest(){

    }

    public RpcRequest(String serviceGroup,String interfaceName,String serviceVersion){
        this.requestKey = new RequestKey(interfaceName,serviceGroup,serviceVersion);
    }

    public RpcRequest(String interfaceName){
        this.requestKey = new RequestKey(interfaceName);
    }


    public String getRequestId() {
        return requestId;
    }

    @Override
    public boolean async() {
        return async;
    }

    @Override
    public boolean hasResult() {
        return hasResult;
    }

    public void setRequestId(String requestId) {
        this.requestId = requestId;
    }

    public RequestKey getRequestKey() {
        return requestKey;
    }

    public void setRequestKey(RequestKey requestKey) {
        this.requestKey = requestKey;
    }

    public String getMethodName() {
        return methodName;
    }

    public void setMethodName(String methodName) {
        this.methodName = methodName;
    }



    public Class<?>[] getParameterTypes() {
        return parameterTypes;
    }

    public void setParameterTypes(Class<?>[] parameterTypes) {
        this.parameterTypes = parameterTypes;
    }

    public Object[] getParameters() {
        return parameters;
    }

    public void setParameters(Object[] parameters) {
        this.parameters = parameters;
    }

    public Map<String, String> getAttach() {
        return attach;
    }

    public void setAttach(Map<String, String> attach) {
        this.attach = attach;
    }

    @Override
    public String toString() {
        return "RpcRequest{" +
                "requestId='" + requestId + '\'' +
                ", requestKey=" + requestKey +
                ", methodName='" + methodName + '\'' +
                ", parameterTypes=" + Arrays.toString(parameterTypes) +
                ", parameters=" + Arrays.toString(parameters) +
                ", attach=" + attach +
                ", timeout=" + timeout +
                ", async=" + async +
                ", hasResult=" + hasResult +
                '}';
    }


}
